import { SetMetadata } from "@nestjs/common";
import cluster from "cluster";

export const CRON_IN_MASTER = "CRON_IN_MASTER";

export const CronInMaster = () => SetMetadata(CRON_IN_MASTER, true);

export const shouldExecute = (target: Object, propertyKey: string | symbol): boolean => {
    if (cluster.isMaster) {
        const isCronInMaster = Reflect.getMetadata(CRON_IN_MASTER, target, propertyKey);
        return Boolean(isCronInMaster);
    }
    return false;
};